package com.mk.service.web;

import act.controller.Controller;
import com.github.d925529.apidoc.annotation.ApiReturn;
import com.mk.domain.ZBrand;
import org.osgl.mvc.annotation.GetAction;
import org.osgl.util.S;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Controller("zBrand")
public class ZBrandService extends BaseWebService {

    @Inject
    private ZBrand.Mapper zBrandMapper;

    @GetAction("list.json")
    @ApiReturn(description = "全部商品类型列表，包含子类型", type = List.class,elementType = ZBrand.class)
    public List<ZBrand> zBrands(){
        List<ZBrand> zBrands = zBrandMapper.brandList();
        List<ZBrand> result = new ArrayList<>();
        zBrands.forEach(zBrand -> {
            if(S.isEmpty(zBrand.getPbrid())){
                List<ZBrand> subList = zBrands.stream().filter(brand->S.eq(brand.getPbrid(),zBrand.getBrid())).collect(Collectors.toList());
                if(subList!=null){
                    zBrand.setSublist(subList);
                }
                result.add(zBrand);
            }
        });
        return result;
    }

}
